package net.chasing.androidbaseconfig.view;

import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.databinding.ViewDataBinding;
import androidx.lifecycle.ViewModelProvider;

import net.chasing.androidbaseconfig.R;

public abstract class BaseFragmentActivity<VM extends BaseViewModel, Binding extends ViewDataBinding>
        extends BaseMVCActivity<Binding> {
    protected VM mViewModel;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mViewModel = new ViewModelProvider(this).get(bindViewModel());
        getLifecycle().addObserver(mViewModel);
        observeData();
        mViewModel.parseIntent(getIntent());
        mViewModel.initResource();
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        if (mViewModel != null)
            mViewModel.parseIntent(intent);
    }

    protected abstract Class<VM> bindViewModel();

    protected abstract void observeData();

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void finish() {
        super.finish();
        overridePendingTransition(R.anim.slide_left_in_20p, R.anim.slide_right_out);
    }
}
